<template>
  <div class="user-wrapper" ref="wrapper">
    <div class="user-contianer">
      <section class="m-top">
        <a @click="userInfo" class="photo" v-if="login">
          <img :src="user.avatar" alt="">
        </a>
        <a @click="openPage('/install')" class="install"><span style="font-size: 18px" class="iconfont icon-setting">
          </span><span>设置</span></a>
        <router-link to="/login" tag='a' v-if="!login" class="login">登录/注册</router-link>
        <p class="username" v-if="login">{{user.nick}}</p>
        <a class="grade" v-if="login"><span class="gradeImg"></span><span>LV <b>0</b></span></a>
      </section>
      <section class="m-con">
        <ul>
          <a @click="openPage('/overage')"><span class="yue"><i class="iconfont icon-yue"></i></span><span>我的余额</span></a>
          <a @click="openPage('/rebate')"><span class="fanli"><i class="iconfont icon-fanli"></i></span><span>返利宝</span></a>
          <a @click="openPage('/partner')"><span class="hehuoren"><i class="iconfont icon-hehuo"></i></span><span>合伙人</span></a>
          <a @click="openPage('/redEnvelopes')"><span class="wodehongbao"><i class="iconfont icon-hongbao"></i></span><span>我的红包</span></a>
          <a @click="openPage('/order')"><span class="dingdan"><i class="iconfont icon-dingdan"></i></span><span>我的订单</span></a>
          <a href="http://jd.fuxids.com"><span class="qianbao"><i class="iconfont icon-qianbao"></i></span><span>我的钱包</span></a>
        </ul>
      </section>
      <section class="m-list">
        <ul>
          <li @click="openPage('/collect')"><span><i class="iconfont icon-wodeshoucang"></i></span><span><p>我的收藏</p><p>我的心有所属</p></span></li>
          <li @click="openPage('/idcart')"><span><i class="iconfont icon-woderenzheng"></i></span><span><p>我的认证</p><p>购物从认证开始</p></span></li>
          <li @click="openPage('/BusinessContract')"><span><i class="iconfont icon-shangjia"></i></span><span><p>商家入驻</p><p>看看我的足迹</p></span></li>
          <li @click="openPage('/checkIn')"><span><i class="iconfont icon-qiandao"></i></span><span><p>签到领积分</p><p>今天你签到了吗?</p></span></li>
        </ul>
      </section>
      <section class="m-nav">
        <a href="tel:4000088761"><span>在线客服</span><span>4000088761</span></a>
        <router-link to="/about"><span>关于我们</span><span class="iconfont icon-right"></span></router-link>
      </section>
    </div>

  </div>
</template>

<script>
  import axios from '../../axios/axios'
  import BScroll from 'better-scroll'

  export default {
    name: 'my',
    data() {
      return {
        login: false,
        user: {}
      }
    },
    components: {},
    mounted: function () {
      var that = this;
      var token = localStorage.getItem('userToken');
      console.log(token);

      this.$root.tokenValidat(token, function (data) {
        if (data) {
          var userdata = JSON.stringify({
            "data": [],
            "controllerName": "userInfo",
            "actionName": "findMyById"
          });
          axios.postAdmain({
            data: userdata,
            callback(res) {
              // console.log(res.data)
              that.user = res.data.data;
            }
          });
          that.login = true;
          // 获取基本认证信息
          console.log('111111');
          var creditData = JSON.stringify({
            'actionName': 'findById',
            'controllerName': 'userAuth',
            'data': []
          });
          axios.postAdmain({
            data: creditData,
            callback(res) {
              console.log(res.data);
              if (res.data.data !== null) {
                sessionStorage.setItem('legalizeInfo', JSON.stringify(res.data.data));
              }
            }
          });
        } else {
          that.login = false;
//          that.$router.push('/login');
        }
      });
      that.$nextTick(() => {
        that._initScroll();
      })
    },
    methods: {
      openPage: function (url) {
        var token = localStorage.getItem('userToken');
        var that = this;
        if (token) {
          this.$root.tokenValidat(token, function (result) {
            if (result) {
              that.$router.push(url);
            } else {
              that.$router.push('/login');
            }
          })
        } else {
          this.$router.push('/login');
        }
      },
      userInfo: function () {
        console.log(this.user.sex);
        var token = localStorage.getItem('userToken');
        var that = this;
        if (token) {
          this.$root.tokenValidat(token, function (result) {
            if (result) {
              that.$router.push({path: '/userInfo', query: {name: that.user.nick, sex: that.user.sex}});
            } else {
              that.$router.push('/login');
            }
          })
        } else {
          this.$router.push('/login');
        }
      },
      _initScroll: function () {
        this.scroll = new BScroll(this.$refs.wrapper, {click: true})
      }
    }
  }
</script>
<style type="text/scss" lang="scss" scoped>
  @import '../../common/style/iconfont.css';

  .user-wrapper {
    width: 100%;
    height: calc(100% - 50px);
    position: absolute;
    top: 0;
    overflow: hidden;
    .user-contianer {
      width: 100%;
      background-color: #FFFFFF;
    }
  }

  .m-top {
    width: 100%;
    height: 60vw;
    border-bottom-right-radius: 50vw 30px;
    border-bottom-left-radius: 50vw 30px;
    position: relative;
    background-image: url('../../common/img/wobg.png');
    background-size: 100% 100%;

  }

  .m-top .photo {
    display: block;
    width: 24vw;
    height: 24vw;
    border-radius: 50%;
    background-color: #fff;
    position: absolute;
    left: 50%;
    top: 8vw;
    margin-left: -12vw;
  }

  .m-top .photo img {
    width: 100%;
    height: 100%;
    border-radius: 50%;
  }

  .m-top .install {
    position: absolute;
    top: 10px;
    right: 20px;
    display: flex;
    flex-direction: column;
    text-align: center;
    color: #fff;
    font-size: 14px;
  }

  .m-top .username {
    display: block;
    width: 24vw;
    height: 24px;
    line-height: 24px;
    position: absolute;
    color: #fff;
    left: 50%;
    top: 36vw;
    margin-left: -12vw;
    text-align: center;
  }

  .m-top .login {
    width: 30vw;
    height: 8vw;
    text-align: center;
    line-height: 8vw;
    border: 1px solid #fff;
    color: red;
    position: absolute;
    left: 50%;
    margin-left: -15vw;
    border-radius: 6px;
    top: 40%;
  }

  .m-top .grade {
    display: block;
    width: 24vw;
    height: 24px;
    line-height: 24px;
    position: absolute;
    left: 50%;
    top: 46vw;
    margin-left: -12vw;
    /*text-align: center;*/
    color: #fff;
    display: flex;
    justify-content: space-between;
  }

  .m-top .grade .gradeImg {
    display: block;
    width: 46px;
    height: 24px;
    background-image: url('../../common/img/grade.png');
    background-size: 100% 100%;
  }

  .m-con {
    width: 100%;
    /*height: 36vw;*/
    background-color: #FFFFFF;
    /*border-bottom: 6px solid #fafafa;*/
    padding-bottom: 20px;
    border-bottom: 5px solid #fafafa;
  }

  .m-con ul {
    display: flex;
    justify-content: space-around;
    flex-wrap: wrap;
    margin-top: 10px;
  }

  .m-con ul a {
    width: 33%;
    text-align: center;
    display: flex;
    flex-direction: column;
    align-items: center;
    font-size: 10px;
    margin-top: 10px;
    span{
      display: block;
    }
    .yue{
      background: linear-gradient(to bottom ,#47b2fb,#0083e6);
    }
    .fanli{
      background: linear-gradient(to bottom , #fc724a, #f93605);
    }
    .hehuoren{
      background: linear-gradient(to bottom , #719bfa, #4977ff);
    }
    .wodehongbao{
      background: linear-gradient(to bottom , #ff5354, #ff4237);
    }
    .dingdan{
      background: linear-gradient(to bottom , #2befed, #13cdcc);
    }
    .qianbao{
      background: linear-gradient(to bottom , #ef8704, #efba01);
    }
    span:first-child {
      width: 11vw;
      height: 11vw;
      border-radius: 8px;
      text-align: center;
      padding-top: 2.5vw;
      box-sizing: border-box;
      margin-bottom: 6px;
      background-color: #6ab2e5;
      i {
        font-size: 6vw;
        color: #FFFFFF;
      }

    }
  }

  .m-list {
    width: 100%;
    /*height: 30vw;*/
    border-bottom: 5px solid #fafafa;
    background-color: #fafafa;
  }

  .m-list ul {
    display: flex;
    justify-content: space-between;
    flex-wrap: wrap;
    background-color: #fafafa;
    font-size: 10px;
  }

  .m-list ul li{
    width: calc((100% - 1px) / 2);
    height: 15vw;
    background-color: #fff;
    margin-top: 1px;
    display: flex;
    justify-content: space-between;
  }

  .m-list ul li span:nth-child(1) {
    display: inline-block;
    width: 34%;
    padding-top: calc((15vw - 30px) / 2);
    text-align: center;
    i{
      color: #d1d1d1;
    }
  }

  .m-list ul li span:nth-child(2) {
    width: 66%;
    height: 14vw;
    display: flex;
    flex-direction: column;
  }

  .m-list ul li span:nth-child(2) p {
    box-sizing: border-box;
  }

  .m-list ul li span:nth-child(2) p:nth-child(1) {
    font-size: 14px;
    padding-top: 8px;
  }

  .m-list ul li span:nth-child(2) p:nth-child(2) {
    color: gray;
    font-size: 10px;
    padding-top: 3px;
  }

  .m-nav {
    width: 100%;
  }

  .m-nav a {
    background-color: #fff;
    display: flex;
    justify-content: space-between;
    align-items: center;
    height: 14vw;
    line-height: 14vw;
    margin-bottom: 1px;
    padding: 0 4vw;
    font-size: 12px;
  }
</style>







